package yxy.cherry.paycenter.servlet.channel;

import java.io.PrintWriter;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSONObject;
import yxy.apple.logger.Logger;

public class Servlet extends HttpServlet {
	static final Logger logger = Logger.create(HttpServlet.class);

	public String getChannel() {
		return null;
	}
	
	public String getUrl() {
		return "/sdk_" + getChannel();
	}
	
	public void returnInfo(JSONObject data, HttpServletResponse resp) {
		logger.info("returnInfo %s", data.toString());
		returnInfo(data.toString(), resp);
	}
	
	/**
	 * 返回信息到渠道
	 * 
	 * @param data
	 * @param resp
	 */
	public void returnInfo(String data, HttpServletResponse resp) {
		PrintWriter pw = null;
		resp.addHeader("Access-Control-Allow-Origin", "*");

		try {
			pw = resp.getWriter();
			pw.write(data);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (pw != null)
				pw.close();
		}
	}
}
